package com.leapp.sk.viewdelegate.adapter.classs

import android.content.Context
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.mvp.view.GlideCircleTransform
import com.example.mvp.view.LKCircleImageView
import com.leapp.sk.R
import com.example.mvp.bean.ClassMemberInfoEntity

/**
 * 班级详情老师适配器视图托管
 * @author  chaohaipeng  on 2018/7/30.
 */
class ClassDetialTecherAdapterDelegate : BaseAdapterDelegate() {
    /**
     * 头像加载操作
     */
    var mHeadRequestOptions: RequestOptions = RequestOptions()

    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.adapter_class_detial_techer
    }

    /**
     * 设置数据
     */
    fun setData(context: Context, data: ClassMemberInfoEntity) {
        val ima_acdt_avatar = getView<LKCircleImageView>(R.id.ima_acdt_avatar)
        val tv_acdt_nick = getView<TextView>(R.id.tv_acdt_nick)
        setHead(context, data.avatar, ima_acdt_avatar)
       // tv_acdt_nick.text = data.nickName

    }

    /**
     * 设置头像和昵称
     */
    private fun setHead(context: Context, headUrl: String?, headImage: LKCircleImageView) {
        val tag = headImage.getTag(R.id.tag_head)
        if (tag == null || !tag?.equals(headUrl)) {
            val mRequestManager = Glide.with(context)
            mHeadRequestOptions?.diskCacheStrategy(DiskCacheStrategy.NONE)
            mHeadRequestOptions?.skipMemoryCache(true)
            mHeadRequestOptions?.error(R.mipmap.icon_defout_head)
            mHeadRequestOptions?.transforms(GlideCircleTransform(context))
            mRequestManager?.load(headUrl)
                    ?.thumbnail(0.2f)
                    ?.apply(mHeadRequestOptions)
                    ?.into(headImage)
            headImage.setTag(R.id.tag_head, headUrl)
        }
    }
}